<template>
  <div class="nav">
    <i @click="setIndex(i)" v-for=" (v,i) in navData" :key="i" :class="[navIdn === i ?  'active':'']">{{v}}</i>
  </div>
</template>
<script>
import navData from '@/datas/nav.js'
import { useStore } from 'vuex'
import { computed } from 'vue'
import loadData from '@/server'
export default {
  name: 'navbar',
  setup() {
    const store = useStore()
    const setIndex = i => {
      store.commit('setConsName', navData[i])
      store.commit('setIndex', i)
      loadData(store)
    }

    return {
      navData,
      navIdn: computed(() => store.state.navIdn),
      setIndex
    }
  }
}
</script>
<style lang="less" scoped>
.nav {
  position: fixed;
  top: 46px;
  left: 0;
  width: 100%;
  height: 36px;
  line-height: 36px;
  font-size: 12px;
  white-space: nowrap;
  overflow-x: auto;
  z-index: 3;
  box-sizing: border-box;
  border-bottom: 1px solid #ccc;
  i {
    width: 40px;
    margin: 0 15px;
  }
}
.nav::-webkit-scrollbar {
  display: none;
}
.active {
  color: #e47e93;
}
</style>
